import { ITime } from "@/data/options/selection";
import { IQuery, IResponse } from "@/interface/IAxios";
import http from "../../config/http";
import { fileTemplate } from "../utils";
import { Goods } from "./types";

// 查询商品信息列表

export function goodsRecordExport(query: ITime) {
  fileTemplate("/goods/record/export", {
    type: query.time,
    value: query.value
  });
}
export function listGoods(query?: IQuery) {
  return http.request({
    url: "/goods/goods/list",
    method: "get",
    params: query
  });
}
// 导出商品信息
export function exportGoods(query?: IQuery) {
  return http.request({
    url: "/goods/goods/export",
    method: "get",
    params: query
  });
}
// 删除商品信息
export function delGoods(goodsId: Array<string>) {
  return http.request({
    url: `/goods/goods/${goodsId}`,
    method: "delete"
  });
}

// 查询商品信息详细
export function getGoods(goodsId: string): Promise<IResponse<Goods>> {
  return http.request({
    url: `/goods/goods/${goodsId}`,
    method: "get"
  });
}
// 修改商品信息
export function updateGoods(data: Goods) {
  return http.request({
    url: "/goods/goods",
    method: "put",
    data
  });
}
export function addGoods(data: Goods) {
  return http.request({
    url: "/goods/goods",
    method: "post",
    data
  });
}
// 查询商品扩展字段
export function findGoodsExpandFields(loadAll = true): Promise<IResponse<Array<any>>> {
  return http.request({
    url: "/goods/goods/findGoodsExpandFields",
    method: "get",
    params: {
      loadAll
    }
  });
}

// 下载导入模板
export function goodsTemplate() {
  return http.request({
    url: "/goods/goods/downImportTemplate",
    method: "get"
  });
}
export const downloadFile = () => {
  return fileTemplate("/goods/goods/export");
};
export const manifestFile = () => {
  return fileTemplate("/goods/goods/manifest?scope=0");
};

/* 将所有商品设为私有或者共享 */
export function setGoodsIsPrivate(isPrivate: 1 | 0) {
  return http.request({
    url: `/goods/goods/touchGenre/${isPrivate}`,
    method: "get"
  });
}

/* 将选定的多个商品设为私有或者共享 */
export function setGoodsIsPrivateBatch(isPrivate: 1 | 0, goodsIds: Array<string>) {
  return http.request({
    url: `/goods/goods/share/${isPrivate}`,
    method: "post",
    data: goodsIds
  });
}

/* 将所有商品设为私有或者共享 */
export function goodsAutoMatch() {
  return http.request({
    url: `/goods/goods/autoMatch`,
    method: "get"
  });
}

/* 将所有商品设为私有或者共享 */
export function removeUrl(id: string) {
  return http.request({
    url: `/goods/goods/removeUrl/${id}`,
    method: "get"
  });
}

/* 将所有商品设为私有或者共享 */
export function goodsRecordList(query: IQuery) {
  return http.request({
    url: `/goods/record/list`,
    method: "get",
    params: query
  });
}
// goods/field/emptyData
export const clearFields = (password: string) => {
  return http.request({
    url: `/goods/field/emptyData`,
    method: "post",
    data: {
      password
    }
  });
};
// goods/field/emptyData
export const clearProduction = (password: string) => {
  return http.request({
    url: `/goods/goods/emptyData`,
    method: "post",
    data: {
      password
    }
  });
};
